/*
* Copyright (C) 2011 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "GLESv1Decoder.h"

#include <EGL/egl.h>
#include <GLES/gl.h>
#include <GLES/glext.h>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

static inline void* SafePointerFromUInt(GLuint value) {
  return (void*)(uintptr_t)value;
}

GLESv1Decoder::GLESv1Decoder()
{
    m_contextData = NULL;
    m_glesDso = NULL;
}

GLESv1Decoder::~GLESv1Decoder()
{
    if (m_glesDso != NULL) {
        delete m_glesDso;
    }
}

void gl1_nullstub() {};

void  GLESv1Decoder::check_Entry() {
	if(!glAlphaFunc) glAlphaFunc = (glAlphaFunc_server_proc_t)gl1_nullstub;
	if(!glClearColor) glClearColor = (glClearColor_server_proc_t)gl1_nullstub;
	if(!glClearDepthf) glClearDepthf = (glClearDepthf_server_proc_t)gl1_nullstub;
	if(!glClipPlanef) glClipPlanef = (glClipPlanef_server_proc_t)gl1_nullstub;
	if(!glColor4f) glColor4f = (glColor4f_server_proc_t)gl1_nullstub;
	if(!glDepthRangef) glDepthRangef = (glDepthRangef_server_proc_t)gl1_nullstub;
	if(!glFogf) glFogf = (glFogf_server_proc_t)gl1_nullstub;
	if(!glFogfv) glFogfv = (glFogfv_server_proc_t)gl1_nullstub;
	if(!glFrustumf) glFrustumf = (glFrustumf_server_proc_t)gl1_nullstub;
	if(!glGetClipPlanef) glGetClipPlanef = (glGetClipPlanef_server_proc_t)gl1_nullstub;
	if(!glGetFloatv) glGetFloatv = (glGetFloatv_server_proc_t)gl1_nullstub;
	if(!glGetLightfv) glGetLightfv = (glGetLightfv_server_proc_t)gl1_nullstub;
	if(!glGetMaterialfv) glGetMaterialfv = (glGetMaterialfv_server_proc_t)gl1_nullstub;
	if(!glGetTexEnvfv) glGetTexEnvfv = (glGetTexEnvfv_server_proc_t)gl1_nullstub;
	if(!glGetTexParameterfv) glGetTexParameterfv = (glGetTexParameterfv_server_proc_t)gl1_nullstub;
	if(!glLightModelf) glLightModelf = (glLightModelf_server_proc_t)gl1_nullstub;
	if(!glLightModelfv) glLightModelfv = (glLightModelfv_server_proc_t)gl1_nullstub;
	if(!glLightf) glLightf = (glLightf_server_proc_t)gl1_nullstub;
	if(!glLightfv) glLightfv = (glLightfv_server_proc_t)gl1_nullstub;
	if(!glLineWidth) glLineWidth = (glLineWidth_server_proc_t)gl1_nullstub;
	if(!glLoadMatrixf) glLoadMatrixf = (glLoadMatrixf_server_proc_t)gl1_nullstub;
	if(!glMaterialf) glMaterialf = (glMaterialf_server_proc_t)gl1_nullstub;
	if(!glMaterialfv) glMaterialfv = (glMaterialfv_server_proc_t)gl1_nullstub;
	if(!glMultMatrixf) glMultMatrixf = (glMultMatrixf_server_proc_t)gl1_nullstub;
	if(!glMultiTexCoord4f) glMultiTexCoord4f = (glMultiTexCoord4f_server_proc_t)gl1_nullstub;
	if(!glNormal3f) glNormal3f = (glNormal3f_server_proc_t)gl1_nullstub;
	if(!glOrthof) glOrthof = (glOrthof_server_proc_t)gl1_nullstub;
	if(!glPointParameterf) glPointParameterf = (glPointParameterf_server_proc_t)gl1_nullstub;
	if(!glPointParameterfv) glPointParameterfv = (glPointParameterfv_server_proc_t)gl1_nullstub;
	if(!glPointSize) glPointSize = (glPointSize_server_proc_t)gl1_nullstub;
	if(!glPolygonOffset) glPolygonOffset = (glPolygonOffset_server_proc_t)gl1_nullstub;
	if(!glRotatef) glRotatef = (glRotatef_server_proc_t)gl1_nullstub;
	if(!glScalef) glScalef = (glScalef_server_proc_t)gl1_nullstub;
	if(!glTexEnvf) glTexEnvf = (glTexEnvf_server_proc_t)gl1_nullstub;
	if(!glTexEnvfv) glTexEnvfv = (glTexEnvfv_server_proc_t)gl1_nullstub;
	if(!glTexParameterf) glTexParameterf = (glTexParameterf_server_proc_t)gl1_nullstub;
	if(!glTexParameterfv) glTexParameterfv = (glTexParameterfv_server_proc_t)gl1_nullstub;
	if(!glTranslatef) glTranslatef = (glTranslatef_server_proc_t)gl1_nullstub;
	if(!glActiveTexture) glActiveTexture = (glActiveTexture_server_proc_t)gl1_nullstub;
	if(!glAlphaFuncx) glAlphaFuncx = (glAlphaFuncx_server_proc_t)gl1_nullstub;
	if(!glBindBuffer) glBindBuffer = (glBindBuffer_server_proc_t)gl1_nullstub;
	if(!glBindTexture) glBindTexture = (glBindTexture_server_proc_t)gl1_nullstub;
	if(!glBlendFunc) glBlendFunc = (glBlendFunc_server_proc_t)gl1_nullstub;
	if(!glBufferData) glBufferData = (glBufferData_server_proc_t)gl1_nullstub;
	if(!glBufferSubData) glBufferSubData = (glBufferSubData_server_proc_t)gl1_nullstub;
	if(!glClear) glClear = (glClear_server_proc_t)gl1_nullstub;
	if(!glClearColorx) glClearColorx = (glClearColorx_server_proc_t)gl1_nullstub;
	if(!glClearDepthx) glClearDepthx = (glClearDepthx_server_proc_t)gl1_nullstub;
	if(!glClearStencil) glClearStencil = (glClearStencil_server_proc_t)gl1_nullstub;
	if(!glClientActiveTexture) glClientActiveTexture = (glClientActiveTexture_server_proc_t)gl1_nullstub;
	if(!glColor4ub) glColor4ub = (glColor4ub_server_proc_t)gl1_nullstub;
	if(!glColor4x) glColor4x = (glColor4x_server_proc_t)gl1_nullstub;
	if(!glColorMask) glColorMask = (glColorMask_server_proc_t)gl1_nullstub;
	if(!glColorPointer) glColorPointer = (glColorPointer_server_proc_t)gl1_nullstub;
	if(!glCompressedTexImage2D) glCompressedTexImage2D = (glCompressedTexImage2D_server_proc_t)gl1_nullstub;
	if(!glCompressedTexSubImage2D) glCompressedTexSubImage2D = (glCompressedTexSubImage2D_server_proc_t)gl1_nullstub;
	if(!glCopyTexImage2D) glCopyTexImage2D = (glCopyTexImage2D_server_proc_t)gl1_nullstub;
	if(!glCopyTexSubImage2D) glCopyTexSubImage2D = (glCopyTexSubImage2D_server_proc_t)gl1_nullstub;
	if(!glCullFace) glCullFace = (glCullFace_server_proc_t)gl1_nullstub;
	if(!glDeleteBuffers) glDeleteBuffers = (glDeleteBuffers_server_proc_t)gl1_nullstub;
	if(!glDeleteTextures) glDeleteTextures = (glDeleteTextures_server_proc_t)gl1_nullstub;
	if(!glDepthFunc) glDepthFunc = (glDepthFunc_server_proc_t)gl1_nullstub;
	if(!glDepthMask) glDepthMask = (glDepthMask_server_proc_t)gl1_nullstub;
	if(!glDepthRangex) glDepthRangex = (glDepthRangex_server_proc_t)gl1_nullstub;
	if(!glDisable) glDisable = (glDisable_server_proc_t)gl1_nullstub;
	if(!glDisableClientState) glDisableClientState = (glDisableClientState_server_proc_t)gl1_nullstub;
	if(!glDrawArrays) glDrawArrays = (glDrawArrays_server_proc_t)gl1_nullstub;
	if(!glDrawElements) glDrawElements = (glDrawElements_server_proc_t)gl1_nullstub;
	if(!glEnable) glEnable = (glEnable_server_proc_t)gl1_nullstub;
	if(!glEnableClientState) glEnableClientState = (glEnableClientState_server_proc_t)gl1_nullstub;
	if(!glFinish) glFinish = (glFinish_server_proc_t)gl1_nullstub;
	if(!glFlush) glFlush = (glFlush_server_proc_t)gl1_nullstub;
	if(!glFogx) glFogx = (glFogx_server_proc_t)gl1_nullstub;
	if(!glFogxv) glFogxv = (glFogxv_server_proc_t)gl1_nullstub;
	if(!glFrontFace) glFrontFace = (glFrontFace_server_proc_t)gl1_nullstub;
	if(!glFrustumx) glFrustumx = (glFrustumx_server_proc_t)gl1_nullstub;
	if(!glGetBooleanv) glGetBooleanv = (glGetBooleanv_server_proc_t)gl1_nullstub;
	if(!glGetBufferParameteriv) glGetBufferParameteriv = (glGetBufferParameteriv_server_proc_t)gl1_nullstub;
	if(!glClipPlanex) glClipPlanex = (glClipPlanex_server_proc_t)gl1_nullstub;
	if(!glGenBuffers) glGenBuffers = (glGenBuffers_server_proc_t)gl1_nullstub;
	if(!glGenTextures) glGenTextures = (glGenTextures_server_proc_t)gl1_nullstub;
	if(!glGetError) glGetError = (glGetError_server_proc_t)gl1_nullstub;
	if(!glGetFixedv) glGetFixedv = (glGetFixedv_server_proc_t)gl1_nullstub;
	if(!glGetIntegerv) glGetIntegerv = (glGetIntegerv_server_proc_t)gl1_nullstub;
	if(!glGetLightxv) glGetLightxv = (glGetLightxv_server_proc_t)gl1_nullstub;
	if(!glGetMaterialxv) glGetMaterialxv = (glGetMaterialxv_server_proc_t)gl1_nullstub;
	if(!glGetPointerv) glGetPointerv = (glGetPointerv_server_proc_t)gl1_nullstub;
	if(!glGetString) glGetString = (glGetString_server_proc_t)gl1_nullstub;
	if(!glGetTexEnviv) glGetTexEnviv = (glGetTexEnviv_server_proc_t)gl1_nullstub;
	if(!glGetTexEnvxv) glGetTexEnvxv = (glGetTexEnvxv_server_proc_t)gl1_nullstub;
	if(!glGetTexParameteriv) glGetTexParameteriv = (glGetTexParameteriv_server_proc_t)gl1_nullstub;
	if(!glGetTexParameterxv) glGetTexParameterxv = (glGetTexParameterxv_server_proc_t)gl1_nullstub;
	if(!glHint) glHint = (glHint_server_proc_t)gl1_nullstub;
	if(!glIsBuffer) glIsBuffer = (glIsBuffer_server_proc_t)gl1_nullstub;
	if(!glIsEnabled) glIsEnabled = (glIsEnabled_server_proc_t)gl1_nullstub;
	if(!glIsTexture) glIsTexture = (glIsTexture_server_proc_t)gl1_nullstub;
	if(!glLightModelx) glLightModelx = (glLightModelx_server_proc_t)gl1_nullstub;
	if(!glLightModelxv) glLightModelxv = (glLightModelxv_server_proc_t)gl1_nullstub;
	if(!glLightx) glLightx = (glLightx_server_proc_t)gl1_nullstub;
	if(!glLightxv) glLightxv = (glLightxv_server_proc_t)gl1_nullstub;
	if(!glLineWidthx) glLineWidthx = (glLineWidthx_server_proc_t)gl1_nullstub;
	if(!glLoadIdentity) glLoadIdentity = (glLoadIdentity_server_proc_t)gl1_nullstub;
	if(!glLoadMatrixx) glLoadMatrixx = (glLoadMatrixx_server_proc_t)gl1_nullstub;
	if(!glLogicOp) glLogicOp = (glLogicOp_server_proc_t)gl1_nullstub;
	if(!glMaterialx) glMaterialx = (glMaterialx_server_proc_t)gl1_nullstub;
	if(!glMaterialxv) glMaterialxv = (glMaterialxv_server_proc_t)gl1_nullstub;
	if(!glMatrixMode) glMatrixMode = (glMatrixMode_server_proc_t)gl1_nullstub;
	if(!glMultMatrixx) glMultMatrixx = (glMultMatrixx_server_proc_t)gl1_nullstub;
	if(!glMultiTexCoord4x) glMultiTexCoord4x = (glMultiTexCoord4x_server_proc_t)gl1_nullstub;
	if(!glNormal3x) glNormal3x = (glNormal3x_server_proc_t)gl1_nullstub;
	if(!glNormalPointer) glNormalPointer = (glNormalPointer_server_proc_t)gl1_nullstub;
	if(!glOrthox) glOrthox = (glOrthox_server_proc_t)gl1_nullstub;
	if(!glPixelStorei) glPixelStorei = (glPixelStorei_server_proc_t)gl1_nullstub;
	if(!glPointParameterx) glPointParameterx = (glPointParameterx_server_proc_t)gl1_nullstub;
	if(!glPointParameterxv) glPointParameterxv = (glPointParameterxv_server_proc_t)gl1_nullstub;
	if(!glPointSizex) glPointSizex = (glPointSizex_server_proc_t)gl1_nullstub;
	if(!glPolygonOffsetx) glPolygonOffsetx = (glPolygonOffsetx_server_proc_t)gl1_nullstub;
	if(!glPopMatrix) glPopMatrix = (glPopMatrix_server_proc_t)gl1_nullstub;
	if(!glPushMatrix) glPushMatrix = (glPushMatrix_server_proc_t)gl1_nullstub;
	if(!glReadPixels) glReadPixels = (glReadPixels_server_proc_t)gl1_nullstub;
	if(!glRotatex) glRotatex = (glRotatex_server_proc_t)gl1_nullstub;
	if(!glSampleCoverage) glSampleCoverage = (glSampleCoverage_server_proc_t)gl1_nullstub;
	if(!glSampleCoveragex) glSampleCoveragex = (glSampleCoveragex_server_proc_t)gl1_nullstub;
	if(!glScalex) glScalex = (glScalex_server_proc_t)gl1_nullstub;
	if(!glScissor) glScissor = (glScissor_server_proc_t)gl1_nullstub;
	if(!glShadeModel) glShadeModel = (glShadeModel_server_proc_t)gl1_nullstub;
	if(!glStencilFunc) glStencilFunc = (glStencilFunc_server_proc_t)gl1_nullstub;
	if(!glStencilMask) glStencilMask = (glStencilMask_server_proc_t)gl1_nullstub;
	if(!glStencilOp) glStencilOp = (glStencilOp_server_proc_t)gl1_nullstub;
	if(!glTexCoordPointer) glTexCoordPointer = (glTexCoordPointer_server_proc_t)gl1_nullstub;
	if(!glTexEnvi) glTexEnvi = (glTexEnvi_server_proc_t)gl1_nullstub;
	if(!glTexEnvx) glTexEnvx = (glTexEnvx_server_proc_t)gl1_nullstub;
	if(!glTexEnviv) glTexEnviv = (glTexEnviv_server_proc_t)gl1_nullstub;
	if(!glTexEnvxv) glTexEnvxv = (glTexEnvxv_server_proc_t)gl1_nullstub;
	if(!glTexImage2D) glTexImage2D = (glTexImage2D_server_proc_t)gl1_nullstub;
	if(!glTexParameteri) glTexParameteri = (glTexParameteri_server_proc_t)gl1_nullstub;
	if(!glTexParameterx) glTexParameterx = (glTexParameterx_server_proc_t)gl1_nullstub;
	if(!glTexParameteriv) glTexParameteriv = (glTexParameteriv_server_proc_t)gl1_nullstub;
	if(!glTexParameterxv) glTexParameterxv = (glTexParameterxv_server_proc_t)gl1_nullstub;
	if(!glTexSubImage2D) glTexSubImage2D = (glTexSubImage2D_server_proc_t)gl1_nullstub;
	if(!glTranslatex) glTranslatex = (glTranslatex_server_proc_t)gl1_nullstub;
	if(!glVertexPointer) glVertexPointer = (glVertexPointer_server_proc_t)gl1_nullstub;
	if(!glViewport) glViewport = (glViewport_server_proc_t)gl1_nullstub;
	if(!glPointSizePointerOES) glPointSizePointerOES = (glPointSizePointerOES_server_proc_t)gl1_nullstub;
	if(!glVertexPointerOffset) glVertexPointerOffset = (glVertexPointerOffset_server_proc_t)gl1_nullstub;
	if(!glColorPointerOffset) glColorPointerOffset = (glColorPointerOffset_server_proc_t)gl1_nullstub;
	if(!glNormalPointerOffset) glNormalPointerOffset = (glNormalPointerOffset_server_proc_t)gl1_nullstub;
	if(!glPointSizePointerOffset) glPointSizePointerOffset = (glPointSizePointerOffset_server_proc_t)gl1_nullstub;
	if(!glTexCoordPointerOffset) glTexCoordPointerOffset = (glTexCoordPointerOffset_server_proc_t)gl1_nullstub;
	if(!glWeightPointerOffset) glWeightPointerOffset = (glWeightPointerOffset_server_proc_t)gl1_nullstub;
	if(!glMatrixIndexPointerOffset) glMatrixIndexPointerOffset = (glMatrixIndexPointerOffset_server_proc_t)gl1_nullstub;
	if(!glVertexPointerData) glVertexPointerData = (glVertexPointerData_server_proc_t)gl1_nullstub;
	if(!glColorPointerData) glColorPointerData = (glColorPointerData_server_proc_t)gl1_nullstub;
	if(!glNormalPointerData) glNormalPointerData = (glNormalPointerData_server_proc_t)gl1_nullstub;
	if(!glTexCoordPointerData) glTexCoordPointerData = (glTexCoordPointerData_server_proc_t)gl1_nullstub;
	if(!glPointSizePointerData) glPointSizePointerData = (glPointSizePointerData_server_proc_t)gl1_nullstub;
	if(!glWeightPointerData) glWeightPointerData = (glWeightPointerData_server_proc_t)gl1_nullstub;
	if(!glMatrixIndexPointerData) glMatrixIndexPointerData = (glMatrixIndexPointerData_server_proc_t)gl1_nullstub;
	if(!glDrawElementsOffset) glDrawElementsOffset = (glDrawElementsOffset_server_proc_t)gl1_nullstub;
	if(!glDrawElementsData) glDrawElementsData = (glDrawElementsData_server_proc_t)gl1_nullstub;
	if(!glGetCompressedTextureFormats) glGetCompressedTextureFormats = (glGetCompressedTextureFormats_server_proc_t)gl1_nullstub;
	if(!glFinishRoundTrip) glFinishRoundTrip = (glFinishRoundTrip_server_proc_t)gl1_nullstub;
	if(!glBlendEquationSeparateOES) glBlendEquationSeparateOES = (glBlendEquationSeparateOES_server_proc_t)gl1_nullstub;
	if(!glBlendFuncSeparateOES) glBlendFuncSeparateOES = (glBlendFuncSeparateOES_server_proc_t)gl1_nullstub;
	if(!glBlendEquationOES) glBlendEquationOES = (glBlendEquationOES_server_proc_t)gl1_nullstub;
	if(!glDrawTexsOES) glDrawTexsOES = (glDrawTexsOES_server_proc_t)gl1_nullstub;
	if(!glDrawTexiOES) glDrawTexiOES = (glDrawTexiOES_server_proc_t)gl1_nullstub;
	if(!glDrawTexxOES) glDrawTexxOES = (glDrawTexxOES_server_proc_t)gl1_nullstub;
	if(!glDrawTexsvOES) glDrawTexsvOES = (glDrawTexsvOES_server_proc_t)gl1_nullstub;
	if(!glDrawTexivOES) glDrawTexivOES = (glDrawTexivOES_server_proc_t)gl1_nullstub;
	if(!glDrawTexxvOES) glDrawTexxvOES = (glDrawTexxvOES_server_proc_t)gl1_nullstub;
	if(!glDrawTexfOES) glDrawTexfOES = (glDrawTexfOES_server_proc_t)gl1_nullstub;
	if(!glDrawTexfvOES) glDrawTexfvOES = (glDrawTexfvOES_server_proc_t)gl1_nullstub;
	if(!glEGLImageTargetTexture2DOES) glEGLImageTargetTexture2DOES = (glEGLImageTargetTexture2DOES_server_proc_t)gl1_nullstub;
	if(!glEGLImageTargetRenderbufferStorageOES) glEGLImageTargetRenderbufferStorageOES = (glEGLImageTargetRenderbufferStorageOES_server_proc_t)gl1_nullstub;
	if(!glAlphaFuncxOES) glAlphaFuncxOES = (glAlphaFuncxOES_server_proc_t)gl1_nullstub;
	if(!glClearColorxOES) glClearColorxOES = (glClearColorxOES_server_proc_t)gl1_nullstub;
	if(!glClearDepthxOES) glClearDepthxOES = (glClearDepthxOES_server_proc_t)gl1_nullstub;
	if(!glClipPlanexOES) glClipPlanexOES = (glClipPlanexOES_server_proc_t)gl1_nullstub;
	if(!glClipPlanexIMG) glClipPlanexIMG = (glClipPlanexIMG_server_proc_t)gl1_nullstub;
	if(!glColor4xOES) glColor4xOES = (glColor4xOES_server_proc_t)gl1_nullstub;
	if(!glDepthRangexOES) glDepthRangexOES = (glDepthRangexOES_server_proc_t)gl1_nullstub;
	if(!glFogxOES) glFogxOES = (glFogxOES_server_proc_t)gl1_nullstub;
	if(!glFogxvOES) glFogxvOES = (glFogxvOES_server_proc_t)gl1_nullstub;
	if(!glFrustumxOES) glFrustumxOES = (glFrustumxOES_server_proc_t)gl1_nullstub;
	if(!glGetClipPlanexOES) glGetClipPlanexOES = (glGetClipPlanexOES_server_proc_t)gl1_nullstub;
	if(!glGetClipPlanex) glGetClipPlanex = (glGetClipPlanex_server_proc_t)gl1_nullstub;
	if(!glGetFixedvOES) glGetFixedvOES = (glGetFixedvOES_server_proc_t)gl1_nullstub;
	if(!glGetLightxvOES) glGetLightxvOES = (glGetLightxvOES_server_proc_t)gl1_nullstub;
	if(!glGetMaterialxvOES) glGetMaterialxvOES = (glGetMaterialxvOES_server_proc_t)gl1_nullstub;
	if(!glGetTexEnvxvOES) glGetTexEnvxvOES = (glGetTexEnvxvOES_server_proc_t)gl1_nullstub;
	if(!glGetTexParameterxvOES) glGetTexParameterxvOES = (glGetTexParameterxvOES_server_proc_t)gl1_nullstub;
	if(!glLightModelxOES) glLightModelxOES = (glLightModelxOES_server_proc_t)gl1_nullstub;
	if(!glLightModelxvOES) glLightModelxvOES = (glLightModelxvOES_server_proc_t)gl1_nullstub;
	if(!glLightxOES) glLightxOES = (glLightxOES_server_proc_t)gl1_nullstub;
	if(!glLightxvOES) glLightxvOES = (glLightxvOES_server_proc_t)gl1_nullstub;
	if(!glLineWidthxOES) glLineWidthxOES = (glLineWidthxOES_server_proc_t)gl1_nullstub;
	if(!glLoadMatrixxOES) glLoadMatrixxOES = (glLoadMatrixxOES_server_proc_t)gl1_nullstub;
	if(!glMaterialxOES) glMaterialxOES = (glMaterialxOES_server_proc_t)gl1_nullstub;
	if(!glMaterialxvOES) glMaterialxvOES = (glMaterialxvOES_server_proc_t)gl1_nullstub;
	if(!glMultMatrixxOES) glMultMatrixxOES = (glMultMatrixxOES_server_proc_t)gl1_nullstub;
	if(!glMultiTexCoord4xOES) glMultiTexCoord4xOES = (glMultiTexCoord4xOES_server_proc_t)gl1_nullstub;
	if(!glNormal3xOES) glNormal3xOES = (glNormal3xOES_server_proc_t)gl1_nullstub;
	if(!glOrthoxOES) glOrthoxOES = (glOrthoxOES_server_proc_t)gl1_nullstub;
	if(!glPointParameterxOES) glPointParameterxOES = (glPointParameterxOES_server_proc_t)gl1_nullstub;
	if(!glPointParameterxvOES) glPointParameterxvOES = (glPointParameterxvOES_server_proc_t)gl1_nullstub;
	if(!glPointSizexOES) glPointSizexOES = (glPointSizexOES_server_proc_t)gl1_nullstub;
	if(!glPolygonOffsetxOES) glPolygonOffsetxOES = (glPolygonOffsetxOES_server_proc_t)gl1_nullstub;
	if(!glRotatexOES) glRotatexOES = (glRotatexOES_server_proc_t)gl1_nullstub;
	if(!glSampleCoveragexOES) glSampleCoveragexOES = (glSampleCoveragexOES_server_proc_t)gl1_nullstub;
	if(!glScalexOES) glScalexOES = (glScalexOES_server_proc_t)gl1_nullstub;
	if(!glTexEnvxOES) glTexEnvxOES = (glTexEnvxOES_server_proc_t)gl1_nullstub;
	if(!glTexEnvxvOES) glTexEnvxvOES = (glTexEnvxvOES_server_proc_t)gl1_nullstub;
	if(!glTexParameterxOES) glTexParameterxOES = (glTexParameterxOES_server_proc_t)gl1_nullstub;
	if(!glTexParameterxvOES) glTexParameterxvOES = (glTexParameterxvOES_server_proc_t)gl1_nullstub;
	if(!glTranslatexOES) glTranslatexOES = (glTranslatexOES_server_proc_t)gl1_nullstub;
	if(!glIsRenderbufferOES) glIsRenderbufferOES = (glIsRenderbufferOES_server_proc_t)gl1_nullstub;
	if(!glBindRenderbufferOES) glBindRenderbufferOES = (glBindRenderbufferOES_server_proc_t)gl1_nullstub;
	if(!glDeleteRenderbuffersOES) glDeleteRenderbuffersOES = (glDeleteRenderbuffersOES_server_proc_t)gl1_nullstub;
	if(!glGenRenderbuffersOES) glGenRenderbuffersOES = (glGenRenderbuffersOES_server_proc_t)gl1_nullstub;
	if(!glRenderbufferStorageOES) glRenderbufferStorageOES = (glRenderbufferStorageOES_server_proc_t)gl1_nullstub;
	if(!glGetRenderbufferParameterivOES) glGetRenderbufferParameterivOES = (glGetRenderbufferParameterivOES_server_proc_t)gl1_nullstub;
	if(!glIsFramebufferOES) glIsFramebufferOES = (glIsFramebufferOES_server_proc_t)gl1_nullstub;
	if(!glBindFramebufferOES) glBindFramebufferOES = (glBindFramebufferOES_server_proc_t)gl1_nullstub;
	if(!glDeleteFramebuffersOES) glDeleteFramebuffersOES = (glDeleteFramebuffersOES_server_proc_t)gl1_nullstub;
	if(!glGenFramebuffersOES) glGenFramebuffersOES = (glGenFramebuffersOES_server_proc_t)gl1_nullstub;
	if(!glCheckFramebufferStatusOES) glCheckFramebufferStatusOES = (glCheckFramebufferStatusOES_server_proc_t)gl1_nullstub;
	if(!glFramebufferRenderbufferOES) glFramebufferRenderbufferOES = (glFramebufferRenderbufferOES_server_proc_t)gl1_nullstub;
	if(!glFramebufferTexture2DOES) glFramebufferTexture2DOES = (glFramebufferTexture2DOES_server_proc_t)gl1_nullstub;
	if(!glGetFramebufferAttachmentParameterivOES) glGetFramebufferAttachmentParameterivOES = (glGetFramebufferAttachmentParameterivOES_server_proc_t)gl1_nullstub;
	if(!glGenerateMipmapOES) glGenerateMipmapOES = (glGenerateMipmapOES_server_proc_t)gl1_nullstub;
	if(!glMapBufferOES) glMapBufferOES = (glMapBufferOES_server_proc_t)gl1_nullstub;
	if(!glUnmapBufferOES) glUnmapBufferOES = (glUnmapBufferOES_server_proc_t)gl1_nullstub;
	if(!glGetBufferPointervOES) glGetBufferPointervOES = (glGetBufferPointervOES_server_proc_t)gl1_nullstub;
	if(!glCurrentPaletteMatrixOES) glCurrentPaletteMatrixOES = (glCurrentPaletteMatrixOES_server_proc_t)gl1_nullstub;
	if(!glLoadPaletteFromModelViewMatrixOES) glLoadPaletteFromModelViewMatrixOES = (glLoadPaletteFromModelViewMatrixOES_server_proc_t)gl1_nullstub;
	if(!glMatrixIndexPointerOES) glMatrixIndexPointerOES = (glMatrixIndexPointerOES_server_proc_t)gl1_nullstub;
	if(!glWeightPointerOES) glWeightPointerOES = (glWeightPointerOES_server_proc_t)gl1_nullstub;
	if(!glQueryMatrixxOES) glQueryMatrixxOES = (glQueryMatrixxOES_server_proc_t)gl1_nullstub;
	if(!glDepthRangefOES) glDepthRangefOES = (glDepthRangefOES_server_proc_t)gl1_nullstub;
	if(!glFrustumfOES) glFrustumfOES = (glFrustumfOES_server_proc_t)gl1_nullstub;
	if(!glOrthofOES) glOrthofOES = (glOrthofOES_server_proc_t)gl1_nullstub;
	if(!glClipPlanefOES) glClipPlanefOES = (glClipPlanefOES_server_proc_t)gl1_nullstub;
	if(!glClipPlanefIMG) glClipPlanefIMG = (glClipPlanefIMG_server_proc_t)gl1_nullstub;
	if(!glGetClipPlanefOES) glGetClipPlanefOES = (glGetClipPlanefOES_server_proc_t)gl1_nullstub;
	if(!glClearDepthfOES) glClearDepthfOES = (glClearDepthfOES_server_proc_t)gl1_nullstub;
	if(!glTexGenfOES) glTexGenfOES = (glTexGenfOES_server_proc_t)gl1_nullstub;
	if(!glTexGenfvOES) glTexGenfvOES = (glTexGenfvOES_server_proc_t)gl1_nullstub;
	if(!glTexGeniOES) glTexGeniOES = (glTexGeniOES_server_proc_t)gl1_nullstub;
	if(!glTexGenivOES) glTexGenivOES = (glTexGenivOES_server_proc_t)gl1_nullstub;
	if(!glTexGenxOES) glTexGenxOES = (glTexGenxOES_server_proc_t)gl1_nullstub;
	if(!glTexGenxvOES) glTexGenxvOES = (glTexGenxvOES_server_proc_t)gl1_nullstub;
	if(!glGetTexGenfvOES) glGetTexGenfvOES = (glGetTexGenfvOES_server_proc_t)gl1_nullstub;
	if(!glGetTexGenivOES) glGetTexGenivOES = (glGetTexGenivOES_server_proc_t)gl1_nullstub;
	if(!glGetTexGenxvOES) glGetTexGenxvOES = (glGetTexGenxvOES_server_proc_t)gl1_nullstub;
	if(!glBindVertexArrayOES) glBindVertexArrayOES = (glBindVertexArrayOES_server_proc_t)gl1_nullstub;
	if(!glDeleteVertexArraysOES) glDeleteVertexArraysOES = (glDeleteVertexArraysOES_server_proc_t)gl1_nullstub;
	if(!glGenVertexArraysOES) glGenVertexArraysOES = (glGenVertexArraysOES_server_proc_t)gl1_nullstub;
	if(!glIsVertexArrayOES) glIsVertexArrayOES = (glIsVertexArrayOES_server_proc_t)gl1_nullstub;
	if(!glDiscardFramebufferEXT) glDiscardFramebufferEXT = (glDiscardFramebufferEXT_server_proc_t)gl1_nullstub;
	if(!glMultiDrawArraysEXT) glMultiDrawArraysEXT = (glMultiDrawArraysEXT_server_proc_t)gl1_nullstub;
	if(!glMultiDrawElementsEXT) glMultiDrawElementsEXT = (glMultiDrawElementsEXT_server_proc_t)gl1_nullstub;
	if(!glMultiDrawArraysSUN) glMultiDrawArraysSUN = (glMultiDrawArraysSUN_server_proc_t)gl1_nullstub;
	if(!glMultiDrawElementsSUN) glMultiDrawElementsSUN = (glMultiDrawElementsSUN_server_proc_t)gl1_nullstub;
	if(!glRenderbufferStorageMultisampleIMG) glRenderbufferStorageMultisampleIMG = (glRenderbufferStorageMultisampleIMG_server_proc_t)gl1_nullstub;
	if(!glFramebufferTexture2DMultisampleIMG) glFramebufferTexture2DMultisampleIMG = (glFramebufferTexture2DMultisampleIMG_server_proc_t)gl1_nullstub;
	if(!glDeleteFencesNV) glDeleteFencesNV = (glDeleteFencesNV_server_proc_t)gl1_nullstub;
	if(!glGenFencesNV) glGenFencesNV = (glGenFencesNV_server_proc_t)gl1_nullstub;
	if(!glIsFenceNV) glIsFenceNV = (glIsFenceNV_server_proc_t)gl1_nullstub;
	if(!glTestFenceNV) glTestFenceNV = (glTestFenceNV_server_proc_t)gl1_nullstub;
	if(!glGetFenceivNV) glGetFenceivNV = (glGetFenceivNV_server_proc_t)gl1_nullstub;
	if(!glFinishFenceNV) glFinishFenceNV = (glFinishFenceNV_server_proc_t)gl1_nullstub;
	if(!glSetFenceNV) glSetFenceNV = (glSetFenceNV_server_proc_t)gl1_nullstub;
	if(!glGetDriverControlsQCOM) glGetDriverControlsQCOM = (glGetDriverControlsQCOM_server_proc_t)gl1_nullstub;
	if(!glGetDriverControlStringQCOM) glGetDriverControlStringQCOM = (glGetDriverControlStringQCOM_server_proc_t)gl1_nullstub;
	if(!glEnableDriverControlQCOM) glEnableDriverControlQCOM = (glEnableDriverControlQCOM_server_proc_t)gl1_nullstub;
	if(!glDisableDriverControlQCOM) glDisableDriverControlQCOM = (glDisableDriverControlQCOM_server_proc_t)gl1_nullstub;
	if(!glExtGetTexturesQCOM) glExtGetTexturesQCOM = (glExtGetTexturesQCOM_server_proc_t)gl1_nullstub;
	if(!glExtGetBuffersQCOM) glExtGetBuffersQCOM = (glExtGetBuffersQCOM_server_proc_t)gl1_nullstub;
	if(!glExtGetRenderbuffersQCOM) glExtGetRenderbuffersQCOM = (glExtGetRenderbuffersQCOM_server_proc_t)gl1_nullstub;
	if(!glExtGetFramebuffersQCOM) glExtGetFramebuffersQCOM = (glExtGetFramebuffersQCOM_server_proc_t)gl1_nullstub;
	if(!glExtGetTexLevelParameterivQCOM) glExtGetTexLevelParameterivQCOM = (glExtGetTexLevelParameterivQCOM_server_proc_t)gl1_nullstub;
	if(!glExtTexObjectStateOverrideiQCOM) glExtTexObjectStateOverrideiQCOM = (glExtTexObjectStateOverrideiQCOM_server_proc_t)gl1_nullstub;
	if(!glExtGetTexSubImageQCOM) glExtGetTexSubImageQCOM = (glExtGetTexSubImageQCOM_server_proc_t)gl1_nullstub;
	if(!glExtGetBufferPointervQCOM) glExtGetBufferPointervQCOM = (glExtGetBufferPointervQCOM_server_proc_t)gl1_nullstub;
	if(!glExtGetShadersQCOM) glExtGetShadersQCOM = (glExtGetShadersQCOM_server_proc_t)gl1_nullstub;
	if(!glExtGetProgramsQCOM) glExtGetProgramsQCOM = (glExtGetProgramsQCOM_server_proc_t)gl1_nullstub;
	if(!glExtIsProgramBinaryQCOM) glExtIsProgramBinaryQCOM = (glExtIsProgramBinaryQCOM_server_proc_t)gl1_nullstub;
	if(!glExtGetProgramBinarySourceQCOM) glExtGetProgramBinarySourceQCOM = (glExtGetProgramBinarySourceQCOM_server_proc_t)gl1_nullstub;
	if(!glStartTilingQCOM) glStartTilingQCOM = (glStartTilingQCOM_server_proc_t)gl1_nullstub;
	if(!glEndTilingQCOM) glEndTilingQCOM = (glEndTilingQCOM_server_proc_t)gl1_nullstub;
}

int GLESv1Decoder::initGL(get_proc_func_t getProcFunc, void *getProcFuncData)
{

	this->initDispatchByName(getProcFunc, getProcFuncData);

    glGetCompressedTextureFormats = s_glGetCompressedTextureFormats;
    glVertexPointerOffset = s_glVertexPointerOffset;
    glColorPointerOffset = s_glColorPointerOffset;
    glNormalPointerOffset = s_glNormalPointerOffset;
    glTexCoordPointerOffset = s_glTexCoordPointerOffset;
    glPointSizePointerOffset = s_glPointSizePointerOffset;
    glWeightPointerOffset = s_glWeightPointerOffset;
    glMatrixIndexPointerOffset = s_glMatrixIndexPointerOffset;

    glVertexPointerData = s_glVertexPointerData;
    glColorPointerData = s_glColorPointerData;
    glNormalPointerData = s_glNormalPointerData;
    glTexCoordPointerData = s_glTexCoordPointerData;
    glPointSizePointerData = s_glPointSizePointerData;
    glWeightPointerData = s_glWeightPointerData;
    glMatrixIndexPointerData = s_glMatrixIndexPointerData;

    glDrawElementsOffset = s_glDrawElementsOffset;
    glDrawElementsData = s_glDrawElementsData;
    glFinishRoundTrip = s_glFinishRoundTrip;

    return 0;
}

int GLESv1Decoder::s_glFinishRoundTrip(void *self)
{
    GLESv1Decoder *ctx = (GLESv1Decoder *)self;
    ctx->glFinish();
    return 0;
}

void GLESv1Decoder::s_glVertexPointerOffset(void *self, GLint size, GLenum type, GLsizei stride, GLuint offset)
{
    GLESv1Decoder *ctx = (GLESv1Decoder *)self;
    ctx->glVertexPointer(size, type, stride, SafePointerFromUInt(offset));
}

void GLESv1Decoder::s_glColorPointerOffset(void *self, GLint size, GLenum type, GLsizei stride, GLuint offset)
{
    GLESv1Decoder *ctx = (GLESv1Decoder *)self;
    ctx->glColorPointer(size, type, stride, SafePointerFromUInt(offset));
}

void GLESv1Decoder::s_glTexCoordPointerOffset(void *self, GLint size, GLenum type, GLsizei stride, GLuint offset)
{
    GLESv1Decoder *ctx = (GLESv1Decoder *)self;
    ctx->glTexCoordPointer(size, type, stride, SafePointerFromUInt(offset));
}

void GLESv1Decoder::s_glNormalPointerOffset(void *self, GLenum type, GLsizei stride, GLuint offset)
{
    GLESv1Decoder *ctx = (GLESv1Decoder *)self;
    ctx->glNormalPointer(type, stride, SafePointerFromUInt(offset));
}

void GLESv1Decoder::s_glPointSizePointerOffset(void *self, GLenum type, GLsizei stride, GLuint offset)
{
    GLESv1Decoder *ctx = (GLESv1Decoder *)self;
    ctx->glPointSizePointerOES(type, stride, SafePointerFromUInt(offset));
}

void GLESv1Decoder::s_glWeightPointerOffset(void * self, GLint size, GLenum type, GLsizei stride, GLuint offset)
{
    GLESv1Decoder *ctx = (GLESv1Decoder *)self;
    ctx->glWeightPointerOES(size, type, stride, SafePointerFromUInt(offset));
}

void GLESv1Decoder::s_glMatrixIndexPointerOffset(void * self, GLint size, GLenum type, GLsizei stride, GLuint offset)
{
    GLESv1Decoder *ctx = (GLESv1Decoder *)self;
    ctx->glMatrixIndexPointerOES(size, type, stride, SafePointerFromUInt(offset));
}



#define STORE_POINTER_DATA_OR_ABORT(location)    \
    if (ctx->m_contextData != NULL) {   \
        ctx->m_contextData->storePointerData((location), data, datalen); \
    } else { \
        return; \
    }

void GLESv1Decoder::s_glVertexPointerData(void *self, GLint size, GLenum type, GLsizei stride, void *data, GLuint datalen)
{
    GLESv1Decoder *ctx = (GLESv1Decoder *)self;

    STORE_POINTER_DATA_OR_ABORT(GLDecoderContextData::VERTEX_LOCATION);

    ctx->glVertexPointer(size, type, 0, ctx->m_contextData->pointerData(GLDecoderContextData::VERTEX_LOCATION));
}

void GLESv1Decoder::s_glColorPointerData(void *self, GLint size, GLenum type, GLsizei stride, void *data, GLuint datalen)
{
    GLESv1Decoder *ctx = (GLESv1Decoder *)self;

    STORE_POINTER_DATA_OR_ABORT(GLDecoderContextData::COLOR_LOCATION);

    ctx->glColorPointer(size, type, 0, ctx->m_contextData->pointerData(GLDecoderContextData::COLOR_LOCATION));
}

void GLESv1Decoder::s_glTexCoordPointerData(void *self, GLint unit, GLint size, GLenum type, GLsizei stride, void *data, GLuint datalen)
{
    GLESv1Decoder *ctx = (GLESv1Decoder *)self;
    STORE_POINTER_DATA_OR_ABORT((GLDecoderContextData::PointerDataLocation)
                                (GLDecoderContextData::TEXCOORD0_LOCATION + unit));

    ctx->glTexCoordPointer(size, type, 0,
                           ctx->m_contextData->pointerData((GLDecoderContextData::PointerDataLocation)
                                                           (GLDecoderContextData::TEXCOORD0_LOCATION + unit)));
}

void GLESv1Decoder::s_glNormalPointerData(void *self, GLenum type, GLsizei stride, void *data, GLuint datalen)
{
    GLESv1Decoder *ctx = (GLESv1Decoder *)self;

    STORE_POINTER_DATA_OR_ABORT(GLDecoderContextData::NORMAL_LOCATION);

    ctx->glNormalPointer(type, 0, ctx->m_contextData->pointerData(GLDecoderContextData::NORMAL_LOCATION));
}

void GLESv1Decoder::s_glPointSizePointerData(void *self, GLenum type, GLsizei stride, void *data, GLuint datalen)
{
    GLESv1Decoder *ctx = (GLESv1Decoder *)self;

    STORE_POINTER_DATA_OR_ABORT(GLDecoderContextData::POINTSIZE_LOCATION);

    ctx->glPointSizePointerOES(type, 0, ctx->m_contextData->pointerData(GLDecoderContextData::POINTSIZE_LOCATION));
}

void GLESv1Decoder::s_glWeightPointerData(void * self, GLint size, GLenum type, GLsizei stride, void * data, GLuint datalen)
{
    GLESv1Decoder *ctx = (GLESv1Decoder *)self;

    STORE_POINTER_DATA_OR_ABORT(GLDecoderContextData::WEIGHT_LOCATION);

    ctx->glWeightPointerOES(size, type, 0, ctx->m_contextData->pointerData(GLDecoderContextData::WEIGHT_LOCATION));
}

void GLESv1Decoder::s_glMatrixIndexPointerData(void * self, GLint size, GLenum type, GLsizei stride, void * data, GLuint datalen)
{
    GLESv1Decoder *ctx = (GLESv1Decoder *)self;

    STORE_POINTER_DATA_OR_ABORT(GLDecoderContextData::MATRIXINDEX_LOCATION);

    ctx->glMatrixIndexPointerOES(size, type, 0, ctx->m_contextData->pointerData(GLDecoderContextData::MATRIXINDEX_LOCATION));
}

void GLESv1Decoder::s_glDrawElementsOffset(void *self, GLenum mode, GLsizei count, GLenum type, GLuint offset)
{
    GLESv1Decoder *ctx = (GLESv1Decoder *)self;
    ctx->glDrawElements(mode, count, type, SafePointerFromUInt(offset));
}

void GLESv1Decoder::s_glDrawElementsData(void *self, GLenum mode, GLsizei count, GLenum type, void * data, GLuint datalen)
{
    GLESv1Decoder *ctx = (GLESv1Decoder *)self;
    ctx->glDrawElements(mode, count, type, data);
}

void GLESv1Decoder::s_glGetCompressedTextureFormats(void *self, GLint count, GLint *data)
{
    GLESv1Decoder *ctx = (GLESv1Decoder *) self;
    ctx->glGetIntegerv(GL_COMPRESSED_TEXTURE_FORMATS, data);
}

void *GLESv1Decoder::s_getProc(const char *name, void *userData)
{
    GLESv1Decoder *ctx = (GLESv1Decoder *)userData;

    if (ctx == NULL || ctx->m_glesDso == NULL) {
        return NULL;
    }

    void *func = NULL;
#ifdef USE_EGL_GETPROCADDRESS
    func = (void *) eglGetProcAddress(name);
#endif
    if (func == NULL) {
        func = (void *)(ctx->m_glesDso->findSymbol(name));
    }
    return func;
}
